//
//  HeadTableViewCell.m
//  MountEverestFM
//
//  Created by ChenNing on 15/10/30.
//  Copyright © 2015年 chenn. All rights reserved.
//

#import "MusicHeadTableViewCell.h"

@interface MusicHeadTableViewCell()
// 虚拟背景图
@property(nonatomic,strong)UIImageView *cellBgImageView;
@property(nonatomic,strong)UIVisualEffectView *effectView;
// 图分享
@property(nonatomic,strong)UIImageView *headImageView;
// 播放量的背景图
@property(nonatomic,strong)UIImageView *playCountBgImageView;
// 播放量
@property(nonatomic,strong)UILabel *playCountLabel;
// 标题
@property(nonatomic,strong)UILabel *headTitleLabel;
// 头像
@property(nonatomic,strong)UIImageView *headHeadImageView;
// 昵称
@property(nonatomic,strong)UILabel *headNickLabel;
// 文字
@property(nonatomic,strong)UILabel *headContentLabel;

// 箭头
@property(nonatomic,strong)UIImageView *headArrowsImageView;

// 分割线
@property(nonatomic,strong)UIImageView *divisionImageView;


@end

@implementation MusicHeadTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.cellBgImageView = [[UIImageView alloc] init];
        _cellBgImageView.userInteractionEnabled = YES;
        //  创建需要的毛玻璃特效类型
        UIBlurEffect *blurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleDark];
        //  毛玻璃view 视图
        self.effectView = [[UIVisualEffectView alloc] initWithEffect:blurEffect];
        //  设置模糊透明度
        self.effectView.alpha = 0.9;
        [self.cellBgImageView addSubview:_effectView];
        [self.contentView addSubview:_cellBgImageView];
        
        self.headImageView = [[UIImageView alloc] init];
        [self.cellBgImageView addSubview:_headImageView];
        
        self.playCountBgImageView = [[UIImageView alloc] init];
        [self.headImageView addSubview:_playCountBgImageView];
        
        self.playCountLabel = [[UILabel alloc] init];
        self.playCountLabel.font = [UIFont systemFontOfSize:13];
        self.playCountLabel.textColor = [UIColor whiteColor];
        self.playCountLabel.textAlignment = NSTextAlignmentCenter;
        [self.playCountBgImageView addSubview:_playCountLabel];
        
        self.headTitleLabel = [[UILabel alloc] init];
        [self.cellBgImageView addSubview:_headTitleLabel];
        
        self.headHeadImageView = [[UIImageView alloc] init];
        [self.cellBgImageView addSubview:_headHeadImageView];
        
        self.headNickLabel = [[UILabel alloc] init];
        self.headNickLabel.textColor = [UIColor whiteColor];
        [self.cellBgImageView addSubview:_headNickLabel];
        
        self.headContentLabel = [[UILabel alloc] init];
        self.headContentLabel.font = [UIFont systemFontOfSize:15];
        self.headContentLabel.textColor = [UIColor lightGrayColor];
        self.headContentLabel.numberOfLines = 0;
        [self.headContentLabel sizeToFit];
        [self.cellBgImageView addSubview:_headContentLabel];
        
        self.headArrowsImageView = [[UIImageView alloc] init];
        [self.cellBgImageView addSubview:_headArrowsImageView];
        
        self.divisionImageView = [[UIImageView alloc] init];
        [self.cellBgImageView addSubview:_divisionImageView];
        
        self.collectButton = [UIButton buttonWithType:UIButtonTypeSystem];
        [self.cellBgImageView addSubview:_collectButton];
        
        self.downloadButton = [UIButton buttonWithType:UIButtonTypeSystem];
        [self.cellBgImageView addSubview:_downloadButton];
        
        self.shareButton = [UIButton buttonWithType:UIButtonTypeSystem];
        [self.cellBgImageView addSubview:_shareButton];

    }
    return self;
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    // 虚拟背景图
    self.cellBgImageView.frame = self.contentView.bounds;
    self.cellBgImageView.contentMode = UIViewContentModeScaleToFill;
    self.effectView.frame = self.contentView.bounds;
    
    // 曲目图
    self.headImageView.frame = CGRectMake(FM_Screen_Pts_Width*10, FM_Screen_Pts_Height*26+FM_Screen_Pts_Height*150+64, (FM_Screen_Width-FM_Screen_Pts_Width*40)/3, (FM_Screen_Width-FM_Screen_Pts_Width*40)/3);
    
    // 播放量背景图
    self.playCountBgImageView.frame = CGRectMake(0, self.headImageView.frame.size.height-FM_Screen_Pts_Height*20, (FM_Screen_Width-FM_Screen_Pts_Width*40)/3, FM_Screen_Pts_Height*20);
    
    // 播放数量
    self.playCountLabel.frame = CGRectMake(FM_Screen_Pts_Width*5, 0, (FM_Screen_Width-FM_Screen_Pts_Width*40)/3-FM_Screen_Pts_Width*10, FM_Screen_Pts_Height*20);
    
    // 头像
    self.headHeadImageView.layer.cornerRadius = FM_Screen_Pts_Width*30/2;
    self.headHeadImageView.layer.masksToBounds = YES;
    self.headHeadImageView.frame = CGRectMake(FM_Screen_Pts_Width*20+(FM_Screen_Width-FM_Screen_Pts_Width*40)/3, FM_Screen_Pts_Height*26+FM_Screen_Pts_Height*150+64, FM_Screen_Pts_Width*30, FM_Screen_Pts_Width*30);
    
    // 昵称
    self.headNickLabel.frame = CGRectMake(FM_Screen_Pts_Width*60+(FM_Screen_Width-FM_Screen_Pts_Width*40)/3, FM_Screen_Pts_Height*26+FM_Screen_Pts_Height*150+64, FM_Screen_Width-(FM_Screen_Pts_Width*40+(FM_Screen_Width-FM_Screen_Pts_Width*40)/3), FM_Screen_Pts_Width*30);
    
    // 说
    self.headContentLabel.frame = CGRectMake(FM_Screen_Pts_Width*20+(FM_Screen_Width-FM_Screen_Pts_Width*40)/3, FM_Screen_Pts_Height*26+FM_Screen_Pts_Height*200+64, FM_Screen_Width-(FM_Screen_Pts_Width*40+(FM_Screen_Width-FM_Screen_Pts_Width*40)/3), ((FM_Screen_Width-FM_Screen_Pts_Width*40)/3)/2);
    
    // 分割线
    self.divisionImageView.frame = CGRectMake(0, FM_Screen_Pts_Height*36+(FM_Screen_Width-FM_Screen_Pts_Width*40)/3+FM_Screen_Pts_Height*150+64, FM_Screen_Width, FM_Screen_Pts_Height*1);
    
    // 收藏
    self.collectButton.frame = CGRectMake((FM_Screen_Width/3-FM_Screen_Pts_Width*105/2)/2, FM_Screen_Pts_Height*46+(FM_Screen_Width-FM_Screen_Pts_Width*40)/3+FM_Screen_Pts_Height*5+FM_Screen_Pts_Height*150+64, FM_Screen_Pts_Width*105/2, FM_Screen_Pts_Height*38/2);
    
    // 下载
    self.downloadButton.frame = CGRectMake(FM_Screen_Width/3+(FM_Screen_Width/3-FM_Screen_Pts_Width*114/2)/2, FM_Screen_Pts_Height*46+(FM_Screen_Width-FM_Screen_Pts_Width*40)/3+FM_Screen_Pts_Height*5+FM_Screen_Pts_Height*150+64, FM_Screen_Pts_Width*114/2, FM_Screen_Pts_Height*32/2);

    // 分享
    self.shareButton.frame = CGRectMake(FM_Screen_Width/3*2+(FM_Screen_Width/3-FM_Screen_Pts_Width*114/2)/2, FM_Screen_Pts_Height*46+(FM_Screen_Width-FM_Screen_Pts_Width*40)/3+FM_Screen_Pts_Height*5+FM_Screen_Pts_Height*150+64, FM_Screen_Pts_Width*114/2, FM_Screen_Pts_Height*32/2);
}

// 赋值
- (void)setHeadDictionary:(NSDictionary *)headDictionary
{
    if (_headDictionary != headDictionary) {
        _headDictionary = headDictionary;
        [self setHeadInfo:headDictionary];
    }
}

// 设置头部数据
- (void)setHeadInfo:(NSDictionary *)headDictionary
{
    
    // 虚拟背景图
    NSURL *headUrl = [NSURL URLWithString:[headDictionary objectForKey:@"coverMiddle"]];
    [self.cellBgImageView sd_setImageWithURL:headUrl];
    
    // 节目图
    NSString *headImageUrl = [headDictionary objectForKey:@"coverOrigin"];
    [self.headImageView sd_setImageWithURL:[NSURL URLWithString:headImageUrl] placeholderImage:[UIImage imageNamed:@"find_kind_btn_default@3x.png"]];
    
    // 播放量
    self.playCountBgImageView.image = [UIImage imageNamed:@"findsubject_title_bg@2x.png"];
    CGFloat playCount = [[headDictionary objectForKey:@"playTimes"] floatValue];
    if (playCount / 10000 > 1) {
        self.playCountLabel.text = [NSString stringWithFormat:@"%.2f 万",(playCount / 10000)];
    }else{
        self.playCountLabel.text = [NSString stringWithFormat:@"%.0f",playCount];
    }
    
    // 头像
    NSString *headHeadImageUrl = [headDictionary objectForKey:@"avatarPath"];
    [self.headHeadImageView sd_setImageWithURL:[NSURL URLWithString:headHeadImageUrl] placeholderImage:[UIImage imageNamed:@"find_kind_btn_default@3x.png"]];
    
    // 昵称
    NSString *headNickStr = [headDictionary objectForKey:@"nickname"];
    self.headNickLabel.text = headNickStr;
    
    // 说
    NSString *headSayStr =  [headDictionary objectForKey:@"tags"];

    self.headContentLabel.text = headSayStr;
    
    // 分割线
    self.divisionImageView.image = [UIImage imageNamed:@"cell_contactlist_line@2x.png"];
    
    // 收藏
//    [self.collectButton setBackgroundImage:[UIImage imageNamed:@"album_collected_non@2x.png"] forState:UIControlStateNormal];
    [self.collectButton setTitle:@"收藏" forState:UIControlStateNormal];
    // 下载
//    [self.downloadButton setBackgroundImage:[UIImage imageNamed:@"album_multiDownload@2x.png"] forState:UIControlStateNormal];
#warning  下载
        [self.downloadButton setTitle:@"" forState:UIControlStateNormal];
    // 分享
//    [self.shareButton setBackgroundImage:[UIImage imageNamed:@"album_share@2x.png"] forState:UIControlStateNormal];
        [self.shareButton setTitle:@"分享" forState:UIControlStateNormal];
    
    
    
    
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    self.contentView.backgroundColor = [UIColor whiteColor];
}

@end
